// DBSrv.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "../engine/core.h"
#include "../engine/ServerCore.h"
#include "../engine/LogMgr.h"
#include "../engine/NetMgr.h"
#include "../engine/GlobalConfig.h"
#include "DBMsgHandler.h"

BOOL ConStruct()
{
	setlocale(LC_ALL, "");
	std::locale::global( std::locale("") );

	CLogMgr::createInstance();
	GAMELOGER->init(LOG4CXX_STR("DB"));	
	GAMELOGER->addConsoleLog();		
	GAMELOGER->addLocalFileLog(LOG4CXX_STR("log\\db.log"));
#ifndef _DEBUG
/*	std::string logger_mode = server_core->getConfig()->mpServerconfig->logger_mode_;
	if ("" != logger_mode)
	{
		GAMELOGER->setLevel(logger_mode);
	}*/
#endif

	CServerCore::createInstance();
	CServerCore::getInstance()->ConConstruct();
	return TRUE;
}

BOOL Initialize()
{
	CClobalConfigMgr::getInstance()->setAppPath(boost::filesystem::current_path());
	CClobalConfigMgr::getInstance()->init("GameDB.xml");
	CNetMgr::getInstance()->StartNet(2);

	CDBMsgHandler::createInstance();
	CServerCore::getInstance()->startNet();
	CServerCore::getInstance()->LoadDB();

	return TRUE;
}

BOOL Run()
{
	return TRUE;
}

void Terminal()
{
	CDBMsgHandler::destroyInstance();
	CServerCore::getInstance()->Terminal();
	CServerCore::destroyInstance();
	CLogMgr::destroyInstance();
}

int _tmain(int argc, _TCHAR* argv[])
{
	if (ConStruct())
	{
		if (Initialize())
		{
			while(Run())
			{
				MYSLEEP(100);
			}
		}
	}

	Terminal();
	return 0;
}
